Skip to content

Conversation

@ShuangShuang0411
Copy link

This pull request includes the complete implementation of AGN feedback for the cool-core destruction project. The key components are:

  1. The AGN feedback module in the ClusterMerger test problem.
  2. The ExactCooling test problem for the currently private ExactCooling source term module.

@hyschive
Copy link
Contributor

hyschive commented Jul 20, 2024

@ShuangShuang0411 Some quick and general comments. I'll check the entire PR thoroughly after it is approved by other reviewers.

  • Make sure that this PR can reproduce the original results of the main branch, including but not limited to the ClusterMerger test. For example,
    • The line # define NCOMP_PASSIVE_BUILTIN2 1 in Macro.h (and other similar lines/files related to cooling). should be activated only when enabling cooling. You may need to add a compilation option in configure.py to control the cooling module. Ask @ChunYen-Chen for details.
    • You have slightly modified some parameters in Input__Parameter (e.g., MU_NORM, MIN_DENS, ...). @jzuhone What do you think about this? If you prefer, we can have different Input__Parameter files (in the same ClusterMerger folder) tailored for different applications.
  • Remove all trailing spaces
  • Replace all tabs with spaces
  • Polish the code format further to conform better with the GAMER style (e.g., indent, code alignment, add empty lines for separating different code segments, add more comments)
  • Fix all the CPU and GPU warning messages during compilation
  • IIRC, dual-energy is important when enabling cooling and/or feedback. Clarify that in README (along with other things that can be important; for example, how to conduct simulations with cooling and feedback in general).

@hyschive
Copy link
Contributor

hyschive commented Jul 20, 2024

@jzuhone Since this PR is most related to your work, could you help review it? I'll also take a close look after you approve it.

First, do you prefer to modify the existing ClusterMerger test (as in the current PR) or add a new test problem?

@hyschive hyschive requested a review from jzuhone July 20, 2024 03:27
@hyschive hyschive assigned jzuhone and hyschive and unassigned hyschive Jul 20, 2024
@hyschive hyschive added enhancement hydro Hydrodynamics test Test problems gpu GPU issues and implementation labels Jul 20, 2024
@jzuhone
Copy link
Collaborator

jzuhone commented Jul 20, 2024

@ShuangShuang0411 @hyschive I plan on reviewing this in detail over the next few days.

Copy link
Collaborator

@jzuhone jzuhone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments.

@jzuhone
Copy link
Collaborator

jzuhone commented Dec 15, 2025

@ChunYen-Chen no, I think it's good for you to include those.

@ChunYen-Chen
Copy link
Collaborator

@jzuhone Could you merge this PR when you have time? This PR includes more scripts, cool-core destruction input files and new initial conditions.

@jzuhone
Copy link
Collaborator

jzuhone commented Dec 15, 2025

@ChunYen-Chen I had a look at it and it looks good, so I merged. Anything else, aside from the conflict that I can fix?

@ChunYen-Chen
Copy link
Collaborator

@jzuhone I think that's all. Thanks for the review.

@jzuhone
Copy link
Collaborator

jzuhone commented Dec 16, 2025

@hyschive I think this is ready for merge!

@hyschive
Copy link
Contributor

@jzuhone @ChunYen-Chen Thanks for your great work updating and reviewing this PR! Please approve it if you think it’s ready.

Since this is a fairly large PR, with 101 files modified, would you mind if I take another look before merging, at least for the files outside the ClusterMerger test problem? I’m unfortunately fully occupied this month, but I should be able to do this in early January. What do you think?

EoS_HTilde2Temp_CPUPtr, EoS_AuxArray_Flt, EoS_AuxArray_Int,
h_EoS_Table );
# endif
if ( Temp <= 5e5 ) mass_cold[c] += fluid_acc[0]*dv;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jzuhone Got it. If the value does not change, hard-coding should be fine.

Copy link
Contributor

@hyschive hyschive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This round of review address several compilation issues introduced by #458. I'll add more comments separately in the coming days.

@hyschive
Copy link
Contributor

@jzuhone Please check my comment here in case you missed it. Also, could you merge the latest main? Thanks.

I'll add more comments on this PR in the coming days.

Copy link
Contributor

@hyschive hyschive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This round of review addresses additional compilation issues and includes a few minor comments.

Copy link
Contributor

@hyschive hyschive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This round of review focuses on the exact-cooling source files.

Copy link
Contributor

@hyschive hyschive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This round of review focuses on the ExactCooling test problem.

jzuhone and others added 8 commits January 21, 2026 10:05
…gamer-fork into cool-core-public

* 'cool-core-public' of ssh://github.com/ShuangShuang0411/gamer-fork:
  Minor
  Update for CCD simulation
  Add more scripts
  Update for CCD simulations
  fix: prevent use of uninitialized variable
  chore(docs): Sync wiki to doc/wiki [skip-cd]
  Update output file
Co-authored-by: Hsi-Yu Schive <hyschive@gmail.com>
Co-authored-by: Hsi-Yu Schive <hyschive@gmail.com>
…gamer-fork into cool-core-public

* 'cool-core-public' of ssh://github.com/ShuangShuang0411/gamer-fork:
  Apply suggestions from code review
  Apply suggestions from code review
* main:
  check pressure only for the EoSs that need
  check pressure only for the EoSs that need
  add a check for pressure in interpolation
  Default FLU_INT_SCHEME based on SUPPORT_SPECTRAL_INT
Co-authored-by: Hsi-Yu Schive <hyschive@gmail.com>
…r.cpp

Co-authored-by: Hsi-Yu Schive <hyschive@gmail.com>
@jzuhone
Copy link
Collaborator

jzuhone commented Jan 21, 2026

@hyschive I believe I have resolved all of your suggestions and I have merged main into this branch.

Copy link
Contributor

@hyschive hyschive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This round of review focuses on the updated ClusterMerger test. Note that the review is not yet complete, and I'll add further comments on this test in the next few days.

if ( FirstTime )
{
const double dh_max = amr->dh[MAX_LEVEL];
if ( R_acc/dh_max <= Threshold[0] )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ( R_acc/dh_max <= Threshold[0] )
if ( R_acc/dh_max <= Threshold[0] && MPI_Rank == 0 )

// flag cells within the target radius, and if the radius is not resolved with a specific number (Threshold[0]) of cells
for (int c=0; c<Merger_Coll_NumHalos; c++)
{
if ( DIST_SQR_3D( Pos, CM_ClusterCen[c] ) <= SQR(25*R_acc) && R_acc/dh <= Threshold[0] )
Copy link
Contributor

@hyschive hyschive Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we regard 25 as a runtime parameter?

{
const double dh_max = amr->dh[MAX_LEVEL];
if ( R_acc/dh_max <= Threshold[0] )
Aux_Message( stderr, "WARNING : MAX_LEVEL is less than the desired refinement level set in Input__Flag_User!! dh_max = %13.7e\n", dh_max );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Aux_Message( stderr, "WARNING : MAX_LEVEL is less than the desired refinement level set in Input__Flag_User!! dh_max = %13.7e\n", dh_max );
Aux_Message( stderr, "WARNING : MAX_LEVEL (%d) is less than the desired refinement level set in Input__Flag_User (R_acc = %13.7e, dh_max = %13.7e, Threshold[0] = %13.7e) !!\n", MAX_LEVEL, R_acc, dh_max, Threshold[0] );

Comment on lines +10 to +11
static char (*Merger_File_Prof)[1000]; // profile table of clusters
char (*Merger_File_Par) [1000]; // particle file of clusters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer replacing 1000 with MAX_STRING, which is defined in Macro.h and set to 512 by default.

// ---------------------------------------------------------------------------------------
// (4) other variables
int AdjustCount = 0; // count the number of adjustments
int Merger_Coll_NumBHs; // number of BHs in the simulation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between this variable and Merger_Coll_NumHalos? It's a bit confusing.

It also looks like Merger_Coll_NumHalos is mainly used during initialization (except for Flag_ClusterMerger.cpp). If so, should we replace it with Merger_Coll_NumBHs (or vice versa) for clarity?

Comment on lines +57 to +58
double (*CM_ClusterCen)[3]; // the center of each cluster
double (*CM_BH_Pos)[3]; // BH position of each cluster
Copy link
Contributor

@hyschive hyschive Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between CM_ClusterCen, CM_BH_Pos, and Merger_Coll_Pos? It's a bit confusing.

In the current implementation, it seems that CM_ClusterCen and CM_BH_Pos are always identical. However, I can imagine cases where the cluster center and the BH position might differ if their definitions change in the future. Adding some comments here would be helpful.

It also looks like Merger_Coll_Pos is only used during initialization. If so, should we replace it with CM_ClusterCen for clarity? Or at least we should add some comments (and perhaps rename Merger_Coll_Pos to for example Merger_Init_Pos for clarification)

bool Flag = false;

// flag cells within the target radius, and if the radius is not resolved with a specific number (Threshold[0]) of cells
for (int c=0; c<Merger_Coll_NumHalos; c++)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be Merger_Coll_NumHalos or Merger_Coll_NumBHs? I'm concerned because after a merger we only reduce Merger_Coll_NumBHs but not Merger_Coll_NumHalos .

// Function : GetClusterCenter
// Description : Get the cluster centers
//
// Note : 1. Must enable Merger_Coll_LabelCenter
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we always call GetClusterCenter(), should we remove the Merger_Coll_LabelCenter option for clarity? Note that the code currently does not raise any error or warning when disabling Merger_Coll_LabelCenter.

Aux_Message( stderr, "WARNING : file \"%s\" already exists !!\n", FileName );

FILE *File_User = fopen( FileName, "a" );
fprintf( File_User, "# ClusterCen_x/y/z : BH position\n" );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarify the units of all parameters.

Copy link
Contributor

@hyschive hyschive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This final round of review adds further comments on the updated ClusterMerger test. Once all comments are addressed, I will perform a final check before merge.

Comment on lines +104 to +106
// rho_gas : Average gas density within the accretion radius
// cs : Average sound speed within the accretion radius
// v_rel : Relative velocity of the gas within the accretion radius and the black hole
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, these three variables refer to “hot” gas. If so, please clarify that.

for (int j=0; j<PS1; j++)
for (int i=0; i<PS1; i++)
{
const double pos2[3] = { amr->patch[0][lv][PID]->EdgeL[0] + (0.5+i)*dh,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason for naming this variable pos2 rather than simply pos?

Comment on lines +1128 to +1130
if ( DIST_SQR_3D( pos2, CM_ClusterCen[c] ) > SQR(R_acc) ) continue;

double dr[3] = { pos2[0]-CM_ClusterCen[c][0], pos2[1]-CM_ClusterCen[c][1], pos2[2]-CM_ClusterCen[c][2] };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DIST_SQR_3D already computes pos2[:]-CM_ClusterCen[c][:]. I suggest removing the redundant calculations.

Comment on lines +1131 to +1133
ang_mom[c][0] += dv * ( dr[1]*amr->patch[FluSg][lv][PID]->fluid[3][k][j][i] - dr[2]*amr->patch[FluSg][lv][PID]->fluid[2][k][j][i] );
ang_mom[c][1] += dv * ( dr[2]*amr->patch[FluSg][lv][PID]->fluid[1][k][j][i] - dr[0]*amr->patch[FluSg][lv][PID]->fluid[3][k][j][i] );
ang_mom[c][2] += dv * ( dr[0]*amr->patch[FluSg][lv][PID]->fluid[2][k][j][i] - dr[1]*amr->patch[FluSg][lv][PID]->fluid[1][k][j][i] );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ang_mom[c][0] += dv * ( dr[1]*amr->patch[FluSg][lv][PID]->fluid[3][k][j][i] - dr[2]*amr->patch[FluSg][lv][PID]->fluid[2][k][j][i] );
ang_mom[c][1] += dv * ( dr[2]*amr->patch[FluSg][lv][PID]->fluid[1][k][j][i] - dr[0]*amr->patch[FluSg][lv][PID]->fluid[3][k][j][i] );
ang_mom[c][2] += dv * ( dr[0]*amr->patch[FluSg][lv][PID]->fluid[2][k][j][i] - dr[1]*amr->patch[FluSg][lv][PID]->fluid[1][k][j][i] );
ang_mom[c][0] += dv * ( dr[1]*amr->patch[FluSg][lv][PID]->fluid[MOMZ][k][j][i] - dr[2]*amr->patch[FluSg][lv][PID]->fluid[MOMY][k][j][i] );
ang_mom[c][1] += dv * ( dr[2]*amr->patch[FluSg][lv][PID]->fluid[MOMX][k][j][i] - dr[0]*amr->patch[FluSg][lv][PID]->fluid[MOMZ][k][j][i] );
ang_mom[c][2] += dv * ( dr[0]*amr->patch[FluSg][lv][PID]->fluid[MOMY][k][j][i] - dr[1]*amr->patch[FluSg][lv][PID]->fluid[MOMX][k][j][i] );


for (int c=0; c<Merger_Coll_NumBHs; c++)
{
MPI_Allreduce( ang_mom[c], ang_mom_sum[c], 3, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems unnecessary to declare ang_mom_sum as a global variable in Init_TestProb_ClusterMerger.cpp. How about making it a local variable in this function instead?

Comment on lines +264 to +267
real P_old_sqr = SQR(fluid[MOMX]) + SQR(fluid[MOMY]) + SQR(fluid[MOMZ]);
real Ekin_old = ( dens_old == 0.0 ) ? (real)0.0 : 0.5*P_old_sqr/dens_old;
real P_new = SQRT( 2*fluid[DENS]*(EngySin + Ekin_old) );
double JetSign = SIGN( Vec_c2m[0]*CM_Jet_Vec[c][0] + Vec_c2m[1]*CM_Jet_Vec[c][1] + Vec_c2m[2]*CM_Jet_Vec[c][2] );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
real P_old_sqr = SQR(fluid[MOMX]) + SQR(fluid[MOMY]) + SQR(fluid[MOMZ]);
real Ekin_old = ( dens_old == 0.0 ) ? (real)0.0 : 0.5*P_old_sqr/dens_old;
real P_new = SQRT( 2*fluid[DENS]*(EngySin + Ekin_old) );
double JetSign = SIGN( Vec_c2m[0]*CM_Jet_Vec[c][0] + Vec_c2m[1]*CM_Jet_Vec[c][1] + Vec_c2m[2]*CM_Jet_Vec[c][2] );
const real P_old_sqr = SQR(fluid[MOMX]) + SQR(fluid[MOMY]) + SQR(fluid[MOMZ]);
const real Ekin_old = ( dens_old == (real)0.0 ) ? (real)0.0 : (real)0.5*P_old_sqr/dens_old;
const real P_new = SQRT( (real)2.0*fluid[DENS]*(EngySin + Ekin_old) );
const real JetSign = SIGN( Vec_c2m[0]*CM_Jet_Vec[c][0] + Vec_c2m[1]*CM_Jet_Vec[c][1] + Vec_c2m[2]*CM_Jet_Vec[c][2] );

real P_new = SQRT( 2*fluid[DENS]*(EngySin + Ekin_old) );
double JetSign = SIGN( Vec_c2m[0]*CM_Jet_Vec[c][0] + Vec_c2m[1]*CM_Jet_Vec[c][1] + Vec_c2m[2]*CM_Jet_Vec[c][2] );

double P_old_perp[3], P_old_para, P_new_para;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
double P_old_perp[3], P_old_para, P_new_para;
real P_old_perp[3], P_old_para, P_new_para;

fluid[MOMY] += CM_BH_Vel[c][1] * fluid[DENS];
fluid[MOMZ] += CM_BH_Vel[c][2] * fluid[DENS];

fluid[ENGY] = 0.5 * (SQR(fluid[MOMX]) + SQR(fluid[MOMY]) + SQR(fluid[MOMZ])) / fluid[DENS] +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fluid[ENGY] = 0.5 * (SQR(fluid[MOMX]) + SQR(fluid[MOMY]) + SQR(fluid[MOMZ])) / fluid[DENS] +
fluid[ENGY] = (real)0.5 * (SQR(fluid[MOMX]) + SQR(fluid[MOMY]) + SQR(fluid[MOMZ])) / fluid[DENS] +


Cool-core destruction:
========================================
Reproduce the cool-core destruction results. Shuang-Shuang Chen (arXiv:2412.13595)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Reproduce the cool-core destruction results. Shuang-Shuang Chen (arXiv:2412.13595)
Reproduce the cool-core destruction results of Chen et al. 2026 (arXiv:2412.13595)

0. Please contact Prof. Hsi-Yu Schive regarding the unreleased exact cooling feature.
1. `sh download_ic_cool_core_destruction.sh`
2. `sh setup_input_files.sh <case_number>`
--> For the high resolution case, please link or copy the input files from
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
--> For the high resolution case, please link or copy the input files from
--> For the high-resolution case, please link or copy the input files from

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement gpu GPU issues and implementation hydro Hydrodynamics test Test problems

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants